//
//  PageButtonsCell.m
//  HappyStore
//
//  Created by 李小辉 on 16/7/11.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "PageButtonsCell.h"

@interface PageButtonsCell ()

@property (strong, nonatomic) UIScrollView *scrollView;
@property (strong, nonatomic) UIPageControl *pageControl;
@end

@implementation PageButtonsCell




- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        NSArray *imageAry = @[@"首页-找项目",@"首页-供应链",@"首页-找人脉",@"首页-ppp",
                              @"首页-活动",@"首页-找资金",@"首页-企业服务",@"首页-政商参考",@"首页-招聘求职",@"首页-招投标"
                              ];
        self.muBtnAry = [NSMutableArray array];
        self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, screenW, 180)];
        self.scrollView.showsHorizontalScrollIndicator = NO;//隐藏水平滑动条
        self.scrollView.bounces = NO;//不回弹
        self.scrollView.pagingEnabled = YES;//打开分页显示
        self.scrollView.backgroundColor = [UIColor whiteColor];
        self.scrollView.contentSize = CGSizeMake(screenW * 2, 0);
        self.scrollView.delegate = self;
        for (int i = 0; i < imageAry.count; i++) {
            UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(i % 6 *82 +16, i / 6 * 78 +12, 44, 58)];
            button.tag = 30 + i;
            [button setImage:[UIImage imageNamed:imageAry[i]] forState:UIControlStateNormal];
            [self.scrollView addSubview:button];
            [self.muBtnAry addObject:button];
        }
        self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(screenW/2-30, 160 , 60, 20)];
       
        self.pageControl.numberOfPages = 2;
        self.pageControl.currentPage = 0;
        
        self.pageControl.currentPageIndicatorTintColor = RGB(194, 192, 193);
        self.pageControl.pageIndicatorTintColor = RGB(235, 235, 235);
        self.frame = CGRectMake(0, 0, screenW, 180);
        [self.pageControl addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.scrollView];
        [self addSubview:self.pageControl];
    }
    
    return self;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGPoint offset = scrollView.contentOffset;
    self.pageControl.currentPage = offset.x/screenW;
}

- (void)changePage:(UIPageControl *)pageControl{
    [UIView animateWithDuration:0.3f animations:^{
        self.scrollView.contentOffset = CGPointMake(screenW * pageControl.currentPage, 0);
    }];
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
